package com.wy.service.impl.wy;

import com.wy.bean.ComplainBean;
import com.wy.dao.ComplainLogMapper;
import com.wy.dao.ComplainMapper;
import com.wy.model.sys.ComplainEntity;
import com.wy.model.sys.ComplainLog;
import com.wy.service.wy.ComplainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("complainServiceImpl")
public class ComplainServiceImpl implements ComplainService {
    @Autowired
    private ComplainMapper complainMapper;

    @Autowired
    private ComplainLogMapper complainLogMapper;
    @Override
    public void insertComplain(ComplainEntity complainEntity) {
        complainMapper.insert(complainEntity);
    }

    @Override
    public void updateComplain(ComplainEntity complainEntity) {
        complainMapper.updateByPrimaryKey(complainEntity);
    }

    @Override
    public void delComplain(List<String> groupId) {
        complainMapper.deleteByPrimaryKeys(groupId);
    }

    @Override
    public List<ComplainBean> complainList(int pageSize, int start, String content, String type, String status, String operator, String complainTimeStart, String complainTimeEnd,Integer uid,List<String> rids) {
        List<ComplainBean> complainBeanList = complainMapper.complainList(pageSize,start,content,type,status,operator,complainTimeStart,complainTimeEnd,uid,rids);
        for(ComplainBean complainBean : complainBeanList) {
            complainBean.setComplainLogs(complainLogMapper.selectComplainByCid(complainBean.getId()));
        }
        return complainBeanList;
    }

    @Override
    public int complainSize(int pageSize, int start, String content, String type, String status, String operator, String complainTimeStart, String complainTimeEnd,Integer uid,List<String> rids) {
        return complainMapper.complainSize(pageSize,start,content,type,status,operator,complainTimeStart,complainTimeEnd,uid,rids);
    }

    @Override
    public void insertComplainLog(ComplainLog complainLog) {
        complainLog.setComplainDealTime(new Date());
        complainLogMapper.insert(complainLog);
        ComplainEntity complainEntity = complainMapper.selectByPrimaryKey(complainLog.getComplainId());
        complainEntity.setStatus(complainLog.getComplainStatus());
    }
}
